<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      xmlns:th="http://www.thymeleaf.org"
      layout:decorator="backstage/layout">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>新闻管理</title>
</head>
<body>
<div id="content" layout:fragment="content">
<script type="text/javascript" src="../../../admin/ace/js/fuelux/fuelux.spinner.min.js"></script>
<script type="text/javascript" src="../../../admin/ace/js/ace-elements.min.js"></script>
<script type="text/javascript">
		
        $("div").delegate(".btn-setting","click",function(){
            $("#addResult").click();
            return true;
        });      
        $(function(){  
             
        	 $('#loseDiv').click(function(e){  	   		 
     	        window.location.href ="/content/contentList.htm";
     	            
     	    });

            $('.date-picker').datepicker().next().on(ace.click_event, function () {
                $(this).prev().focus();
            });
            $('#spinner2').ace_spinner({value: 0, min: 0, max: 1000000000, step: 100, icon_up: 'icon-caret-up', icon_down: 'icon-caret-down'});
            $('#edit-numberUnit').ace_spinner({value: 0, min: 0, max: 1000000000, step: 100, icon_up: 'icon-caret-up', icon_down: 'icon-caret-down'});
                                   
            
            /* //编辑弹出框        	                               
            var status=$("#edit-status").val();                
            if(status==1){
            	$("#edit-status1").click();
            }else{
            	$("#edit-status2").click();           	
            }
            var type=$("#edit-types").val();                   
            if(type!=""){            	
            	$("#edit-type option[value="+type+"]").attr("selected", "true");
            }        */   
            var type=$("#edit-type option:selected").val();
            showSpecialist(type);
          //时间控件调用
            /* $(".form_datetime").datetimepicker({
            	format: 'yyyy-mm-dd hh:mm',
                autoclose: true
            }); */
            
            var imgUrl=$("#hidden-newsImg").val();
            if(imgUrl==""){
            	imgUrl="没有文件 ...";
            }
            
            $('#edit-newsImg').ace_file_input({
                no_file: imgUrl,
                btn_choose: 'Choose',
                btn_change: 'Change',
                droppable: false,
                onchange: null,
                thumbnail: false//| true | large
//                whitelist:'xls|xlsx'
               //blacklist:'exe|php'
               //onchange:''
            });

           		var imgUrl=$("#hidden-specialistImg").val();
                if(imgUrl==""){
                	imgUrl="没有文件 ...";
                }
                
                $('#edit-specialistImg').ace_file_input({
                    no_file: imgUrl,
                    btn_choose: 'Choose',
                    btn_change: 'Change',
                    droppable: false,
                    onchange: null,
                    thumbnail: false//| true | large
//                    whitelist:'xls|xlsx'
                   //blacklist:'exe|php'
                   //onchange:''
                });
            
            var status=$("#edit-status").val();                
            if(status==1){
            	$("#edit-status1").click();
            }else{
            	$("#edit-status2").click();           	
            }
            
			//提交更新
            $("#editcontent").validate({
                checkStart : true,
                errorElement: 'span',
                errorClass: 'help-inline',
                focusInvalid: false,
                rules : {
                	title : {
                        required: true
                        /* remote:{
                            url: "/tnews/checkTNewsTitle.json",
                            type: "post",
                            data:{
                                id: function() { return $("#edit-id").val()},
                                title: function(){return $("#edit-title").val();}
                            }
                        } */
                    },
                    teamId:{
                    	required:true
                    },
                    type:{
                    	required:true
                    },
                    newsTime:{
                    	required:true
                    },
                    content:{
                    	required:true
                    }
                },
                messages : {
                	title : {
                        required: "请填写标题"
                        //remote: "输入的标题已存在"
                    },
                    teamId:{
                    	required: "请选择球队"
                    },                                      
                    type:{
                    	required: "请选择新闻分类"
                    },
                    newsTime:{
                    	required:"请填写新闻时间"
                    },
                    content:{
                    	required: "必须填写"
                    }
                },
                submitHandler : function(form) {                 	
                	var type=$("#edit-type option:selected").val();
                	if(type==1){
                		if($("#edit-specialist").val()==""){
                			alert("请填写专家名");
                			return false;
                		}
                	}
                    $("#editcontent").ajaxSubmit(function(date,res,me){
                        if(date.suc){
                            alert("操作成功了！");
                            $(".close").click();
                            window.location.href = "/tnews/list.htm";
                        }else {
        	                alert("保存失败了！" + date.msg);
        	            }
                    });
                }, 
                highlight: function (e) {
                    $(e).closest('.control-group').removeClass('info').addClass('error');
                }
            });
            
        });

       function showSpecialist(type){
    	   if(type==1){
    		   $("#specialistDiv").show();
    		   $("#specialistImgDiv").show();
    	   }else{
    		   $("#specialistDiv").hide(); 
    		   $("#specialistImgDiv").hide();
    	   }
       } 
		
		
    </script> 
<!--  发布新闻    -->
	<div class="box-content">
        <div class="row-fluid sortable">
         <div class="box span12" style="height:700px;max-height:700px;">
            <h3 class="row-fluid header smaller lighter blue">
                 <span class="label label-large label-pink arrowed-right" th:text="${tnews.id==null?'新闻添加':'新闻编辑'}"></span>
             </h3>
            <form class="form-horizontal" style="margin: 0" action="/tnews/addOrUpdate.json" method="post" id="editcontent" enctype="multipart/form-data">
                <input id="edit-id" name="id" type="hidden" th:value="${tnews.id}"/>
                <input id="edit-createTime" name="createTime" type="hidden" th:value="${tnews.createTime}"/>
                <input id="edit-createUser" name="createUser" type="hidden" th:value="${tnews.createUser}"/> 
                <input id="edit-status" type="hidden" th:value="${tnews.status}"/>               
                <fieldset>
                    <div class="modal-body" style="height:600px;max-height:600px;">
                        <div class="control-group">
                            <label class="control-label">新闻标题：</label>

                            <div class="controls">
                                <input type="text" name="title" id="edit-title" th:value="${tnews.title}" class="input-xxlarge"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">球队：</label>

                            <div class="controls">
                                <select name="teamId" id="edit-teamId">
                                    <option value="" selected="selected">选择球队</option>                                    
                                   <option th:each="team:${teamList}" 
		            				th:selected="${team.id == tnews.teamId}"  
		            				th:value="${team.id}" th:text="${team.name}">
		            				</option>
                                </select>
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label">新闻分类：</label>

                            <div class="controls">
                                <select name="type" id="edit-type" onchange="showSpecialist(this.value)">
                                    <option value="">选择分类</option>
                                    <option value="1" th:selected="${tnews.type==1}">专家点评</option>    
                                    <option value="2" th:selected="${tnews.type==2}">官网发布</option>    
                                    <option value="3" th:selected="${tnews.type==3}">赛事新闻</option>                                        
                                    <option value="4" th:selected="${tnews.type==4}">场外花絮</option>   
                                </select>
                            </div>
                        </div>
                        <div class="control-group" id="specialistDiv">
                            <label class="control-label">专家名：</label>

                            <div class="controls">
                                <input type="text" name="specialist" id="edit-specialist" th:value="${tnews.specialist}" class="input-xlarge"/>
                            </div>
                        </div>
                        <div class="control-group" id="specialistImgDiv">
                            <label class="control-label">专家头像：</label>

                            <div class="controls">
                            	<div class="widget-main" style="padding:0px;width:220px;">
		                        	<input type="file" id="edit-specialistImg" name="file1" />
		                        	<input type="hidden" id="hidden-specialistImg" th:value="${tnews.specialistImg}"/>
			                    </div>
                            </div>
                        </div>
                        <div class="control-group">
	                        <label class="control-label">新闻时间：</label>
	                        <div class="controls">
	                                <!--  时间控件 -->
							        <!-- <div class="input-append date form_datetime" >
									    <input size="16" type="text" name="newsTime" id="edit-newsTime" th:value="${tnews.newsTime}" readonly="readonly" />
									    <span class="add-on"><i class="icon-remove"></i></span>
									    <span class="add-on"><i class="icon-calendar"></i></span>
									</div> -->
									<input type="text" class="time-link-input" readonly="readonly" name="newsTime" id="edit-newsTime" 
							    		th:value="${tnews.newsTime}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>							    
	                        </div>
                        </div>
                        <div class="control-group">
	                        <label class="control-label">新闻图片：</label>
	                        <div class="controls">
	                            <div class="widget-main" style="padding:0px;width:220px;">
		                        	<input type="file" id="edit-newsImg" name="file" />
		                        	<input type="hidden" id="hidden-newsImg" th:value="${tnews.newsImg}"/>
			                    </div>
	                        </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">新闻内容：</label>

                            <div class="controls">
                                <textarea  id="edit-content" th:text="${tnews.content}" style="width:90%;height:300px;" name="content"></textarea>                               
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">新闻状态：</label>
                            <div class="controls">
	                           	<input type="radio" value="1" name="status" id="edit-status1"/>开启	
	                           	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	                           	<input type="radio" value="2" name="status" id="edit-status2"/>关闭	
	                           	<input type="hidden" th:value="${tnews.status}" id="edit-status"/>
                           	</div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="submit" class="btn btn-primary btn-small" value="保存" name="isEmpty"/>
                        <a href="/tnews/list.htm" class="btn btn-small" data-dismiss="modal">取消</a>
                    </div>
                </fieldset>
            </form>
   		</div>
    </div>
  </div>           
</div>
</body>
</html>